using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using cframework;
using System.ComponentModel;
using Newtonsoft.Json;
using static UnityEngine.EventSystems.EventTrigger;
using System.Reflection;
using System.Linq;

namespace cframework
{
    [CreateAssetMenu(menuName = "cframework/BuildPlayerSetting_IOS")]
    public class BuildPlayerSetting_IOS : BuildPlayerSetting
    {
        [Essential]
        public string teamId;

        public static void SetIosAutoSign(string teamId)
        {
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS)
            {
                bool enable = !string.IsNullOrEmpty(teamId);
                PlayerSettings.iOS.appleEnableAutomaticSigning = enable;
                EditorPrefs.SetBool("DefaultiOSAutomaticallySignBuild", enable);

                PlayerSettings.iOS.appleDeveloperTeamID = teamId;
            }
        }

        public override bool SetPlatformConfig()
        {
            var ret = GetTarget();

            var il2cppCompiler = PlayerSettings.GetIl2CppCompilerConfiguration(ret.Item1);
            if (il2cppCompiler == Il2CppCompilerConfiguration.Release)
            {
                if(EditorUserBuildSettings.development)
                {
                    int option = EditorUtility.DisplayDialogComplex("warning", "development build can't be used, because cppCompiler is release", "set developmentbuild to false", "continue", "cancel");
                    switch(option)
                    {
                        case 0:
                            EditorUserBuildSettings.development = false;
                            break;
                        case 1:
                            break;
                        case 2:
                            return false;

                    }
                }
            }

            SetIosAutoSign(teamId);
            return true;
        }
    }
}